package com.trs.util.task;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;

import com.trs.controll.Controller;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@EnableScheduling
@Configuration
public class TaskPushDD implements SchedulingConfigurer {

	@Value("${cronpushdd}")
	String cronpushdd;

	@Resource
	Controller controller;

	@Override
	public void configureTasks(ScheduledTaskRegistrar task) {
		// task.addCronTask(() -> {
		// try {
		// log.info("定时推送微信登录状态信息到钉钉");
		// controller.checkonline();
		// } catch (Exception e) {
		// log.error("定时推送微信登录状态信息到钉钉异常", e);
		// }
		// }, croncheckonline);

		task.addTriggerTask(() -> {
			try {
				log.info("定时推送微信登录状态信息到钉钉");
				controller.checkonline();
			} catch (Exception e) {
				log.error("定时推送微信登录状态信息到钉钉异常", e);
			}
		}, triggerContext -> {
			return new CronTrigger(cronpushdd).nextExecutionTime(triggerContext);
		});
	}
}
